package com.it.admin.controller;

import com.it.admin.service.AdminTagService;
import com.it.common.aspect.ApiOperationLog;
import com.it.common.utils.PageResponse;
import com.it.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.it.admin.model.dto.tag.AddTagDto;
import com.it.admin.model.dto.tag.DeleteTagDto;
import com.it.admin.model.dto.tag.FindTagPageListDto;
import com.it.admin.model.dto.tag.SearchTagsDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yu
 * @date 2025/01/06
 *
 */
@RestController
@RequestMapping("/admin/tag")
@Api(tags = "Admin 标签模块")
public class AdminTagController {

    @Resource
    private AdminTagService adminTagService;

    @PostMapping("/add")
    @ApiOperation(value = "添加标签")
    @ApiOperationLog(description = "添加标签")
    @PreAuthorize(value = "hasRole('admin')")
    public Response addTag(@RequestBody @Validated AddTagDto addTagDto){

        return adminTagService.addTags(addTagDto);
    }

    @PostMapping("/list")
    @ApiOperation(value = "分页查询")
    @ApiOperationLog(description = "分页查询")
    public PageResponse findTagPageList(@RequestBody @Validated FindTagPageListDto findTagPageListDto){
        return adminTagService.findTagPageList(findTagPageListDto);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除标签")
    @ApiOperationLog(description = "删除标签")
    @PreAuthorize(value = "hasRole('admin')")
    public Response deleteTag(@RequestBody @Validated DeleteTagDto deleteTagDto){
        return adminTagService.deleteTag(deleteTagDto);
    }

    @PostMapping("/search")
    @ApiOperation(value = "标签模糊查询")
    @ApiOperationLog(description = "标签模糊查询")
    public Response searchTags(@RequestBody @Validated SearchTagsDto searchTagsDto){
        return adminTagService.searchTags(searchTagsDto);
    }

    @PostMapping("/select/list")
    @ApiOperation(value = "分类 Select 下拉列表数据获取")
    @ApiOperationLog(description = "分类 Select 下拉列表数据获取")
    public Response findCategorySelectList() {
        return adminTagService.findTagSelectList();
    }

}
